Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

213
Visualizações
Applescript: Safari "Do Javascript" No Longer Returns Booleans?

This used to return either true or false:

tell application "Safari" to do JavaScript "document.querySelector(\"video\") == null" in document 1

However, now, on macOS 12.0.1 on an M1 MBP, it doesn't seem to return anything (missing value) and the following convoluted wrapper seems necessary to get the former result:

tell application "Safari"
    set result to do JavaScript "if (document.querySelector(\"video\") == null) {
   1
} else {
   0
}" in document 1
    return result is 1
end tell

Another weird thing is that it's only booleans that don't get returned. The following returns 3.0:

tell application "Safari" to do JavaScript "3" in document 1

Any idea what changed? Is there a better way to get the boolean result back?

Here is what my Safari Develop tab looks like in case any of those settings are relevant: enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I still don't know why the issue is happening, but here's a temporary workaround in case it helps:

tell application "Safari"
    
    set result to do JavaScript "try {
    var jsResult = document.querySelector(\"video\").paused;

    switch (jsResult) {
    case true:
        jsResult = 'js2as-true';
        break;
    case false:
        jsResult = 'js2as-false';
    }
jsResult
}
catch(err) {
'js2as-error' + err.message
}" in document 1
    
    if (result = "js2as-true") then
        return true
    else if (result = "js2as-false") then
        return false
    else if (result starts with "js2as-error") then
        set errMsg to text 12 thru -1 of result
        error errMsg
    else
        return result
    end if
end tell

One limitation is that it's hard to make generic because you need to explicitly store the return value from the appropriate statement. Another approach might be to insert the script into an anonymous function, but then you'd have to explicitly return aValue

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda